package com.servlet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.Space;
import com.dev.IconView;
import com.dev.MainActivity;
import com.dev.R;
import android.widget.TextView;
import android.util.TypedValue;
import android.view.Gravity;
import android.graphics.Typeface;
import com.dev.ScrollBar;
import java.net.Socket;                                          
public class GUIHttpHost extends LinearLayout implements OnClickListener{
	MainActivity ma;
	public LinearLayout titlebar;
	public IconView ivQuit,ivMenu,ivPR;
    public TextView info1;
    public TextView status;
    public TextView tbPeekZebra;
    public HttpServer ns;
    public ScrollBar sb;
    public GUIHttpHost(MainActivity ma){
		super(ma);
		this.ma=ma;
        tbPeekZebra=new TextView(ma);
        tbPeekZebra.setTextColor(0xff11aaff);
        tbPeekZebra.setGravity(Gravity.CENTER);
        tbPeekZebra.setTextSize(TypedValue.COMPLEX_UNIT_DIP,13);
        tbPeekZebra.setText(" 查看二维码 ");
		ivQuit=new IconView(ma);
		ivQuit.setOnClickListener(this);
		ivQuit.setImageResource(R.drawable.ic_quit_thin);
		ivMenu=new IconView(ma);
		ivMenu.setOnClickListener(this);
		ivMenu.setImageResource(R.drawable.ic_dots_vertical);
        ivPR=new IconView(ma);
        ivPR.setOnClickListener(this);
        ivPR.setImageResource(R.drawable.ic_play);
        info1=new TextView(ma);
        info1.setGravity(Gravity.CENTER);
        info1.setTextColor(0xff00ccff);
        info1.setTypeface(Typeface.MONOSPACE);
        int hintPadding=9;
        sb=new ScrollBar(ma);
        sb.addView(ivPR);
        status=new TextView(ma);
        status.setTextSize(TypedValue.COMPLEX_UNIT_DIP,12);
        status.setGravity(Gravity.CENTER_VERTICAL);
        status.setTypeface(Typeface.MONOSPACE);
        status.setPadding(hintPadding,0,0,0);
        status.setSingleLine();
        status.setTextColor(0xff7f7f7f);
		titlebar=new LinearLayout(ma);
		titlebar.setOrientation(0);
		titlebar.setBackgroundColor(ma.titlebarBackgroundColor);
		titlebar.addView(ivQuit);
		titlebar.addView(new Space(ma),new LayoutParams(0,-1,1f));
		titlebar.addView(ivMenu);
        TextView hint1=new TextView(ma);
        TextView hint2=new TextView(ma);
        hint1.setSingleLine();
        hint1.setTextSize(TypedValue.COMPLEX_UNIT_DIP,13);
        hint1.setText("http服务器地址：");
        hint1.setPadding(hintPadding,0,0,0);
        hint2.setSingleLine();
        hint2.setTextSize(TypedValue.COMPLEX_UNIT_DIP,13);
        LinearLayout line1=new LinearLayout(ma);
        LinearLayout line2=new LinearLayout(ma);
        LayoutParams infolp=new LayoutParams(0,-1,1f);
        line1.setOrientation(0);
        line1.addView(hint1,-2,-1);
        line1.addView(info1,infolp);
        line2.setOrientation(0);
        line2.addView(tbPeekZebra,-2,-1);
		addView(titlebar,-1,ma.titlebarHeight);
        addView(line1,-1,ma.dialogTitleBarHeight);
        addView(line2,-1,ma.dialogTitleBarHeight);
        ns=new HttpServer(ma);
	}
	@Override
	public void onClick(View view) {
		if(view==ivQuit){
			ma.setContentView(ma.gui);
		}else if(view==ivPR){
            if(ns.state==0){
                ns.start();
                ivPR.setImageResource(R.drawable.ic_pause);
            }else if(ns.state==1){
                ns.interrupt();
                ns=new HttpServer(ma);
                ivPR.setImageResource(R.drawable.ic_play);
            }else{
                ns=new HttpServer(ma);
                ns.start();
                ivPR.setImageResource(R.drawable.ic_pause);
            }
        }
	}
}
